package com.collect.zambia.zhiAdater.zhiRecTagAdjuster;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.collect.zambia.R;
import com.collect.zambia.zhiBean.zhiReceive.ZHIRRecTagEntity;

import java.util.List;

public class ZHIRecTagAdjuster extends BaseMultiItemQuickAdapter<ZHIRecTag, BaseViewHolder> {

    public ZHIRecTagAdjuster(List<ZHIRecTag> data) {
        super(data);
        addItemType(ZHIRecTag.TypeNormal, R.layout.item_rec_tag_list_v2);
        addItemType(ZHIRecTag.TypePTP, R.layout.item_rec_tag_ptp_list_v2);
    }

    private OnRecTagItemClickListener mOnRecTagItemClickListener;

    @Override
    protected void convert(BaseViewHolder helper, final ZHIRecTag zhiRecTag) {

        switch (helper.getItemViewType()) {
            case ZHIRecTag.TypeNormal: {
                initTypeNomalView(helper, zhiRecTag);
                break;
            }
            case ZHIRecTag.TypePTP: {
                initTypePTPView(helper, zhiRecTag);
                break;
            }
        }
    }

    private void initTypeNomalView(BaseViewHolder helper, final ZHIRecTag zhiRecTag) {
        if (helper == null) return;
        if (zhiRecTag == null) return;
        ZHIRRecTagEntity ctOption = zhiRecTag.getZhirRecTagEntity();
        if (ctOption == null) return;

        helper.setText(R.id.tv_tagging_sys_user_name, ctOption.getSysUserName());
        helper.setText(R.id.tv_tagging_record_time, ctOption.getDunRecordTime());
        helper.setText(R.id.tv_tagging_record_name, ctOption.getContactName());
        helper.setText(R.id.tv_tagging_record_phone, ctOption.getContactMobileEncryptFormatter());
        helper.setText(R.id.tv_tagging_record_relationship, ctOption.getContactRelation());
        helper.setText(R.id.tv_tagging_record_result, ctOption.getContactResult());
        helper.setText(R.id.tv_tagging_record_remarks, ctOption.getRemark());

        helper.addOnClickListener(R.id.tv_title);

        if (mOnRecTagItemClickListener != null) {
            helper.getView(R.id.tv_title).setOnClickListener(view -> mOnRecTagItemClickListener.OnItemClick(ctOption.getContactName()));
        }
    }


    private void initTypePTPView(BaseViewHolder helper, final ZHIRecTag zhiRecTag) {
        if (helper == null) return;
        if (zhiRecTag == null) return;
        ZHIRRecTagEntity ctOption = zhiRecTag.getZhirRecTagEntity();
        if (ctOption == null) return;

        helper.setText(R.id.tv_tagging_sys_user_name, ctOption.getSysUserName());
        helper.setText(R.id.tv_tagging_record_time, ctOption.getDunRecordTime());
        helper.setText(R.id.tv_tagging_record_name, ctOption.getContactName());
        helper.setText(R.id.tv_tagging_record_phone, ctOption.getContactMobileEncryptFormatter());
        helper.setText(R.id.tv_tagging_record_relationship, ctOption.getContactRelation());
        helper.setText(R.id.tv_tagging_record_result, ctOption.getContactResult());
        helper.setText(R.id.tv_tagging_record_remarks, ctOption.getRemark());

        helper.setText(R.id.tv_promised_due_time, ctOption.getPtpTime());

        helper.addOnClickListener(R.id.tv_title);

        if (mOnRecTagItemClickListener != null) {
            helper.getView(R.id.tv_title).setOnClickListener(view -> mOnRecTagItemClickListener.OnItemClick(ctOption.getContactName()));
        }
    }


    public void setOptionClickListener(OnRecTagItemClickListener optionClickListener) {
        this.mOnRecTagItemClickListener = optionClickListener;
    }

    public interface OnRecTagItemClickListener {
        void OnItemClick(String title);
    }
}